package com.chen.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chen.back.entity.Role;
import com.chen.back.mapper.RoleMapper;
import com.chen.back.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chen
 * @since 2022-02-24
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public Set<String> getAllRoleNamesByUsername(String username) {
        return roleMapper.selectAllRoleNamesByUsername(username);
    }
    //根据角色名得到角色id
  public   Integer getRoleIDBYRoleName(String roleName ){
        return roleMapper.getRoleIDBYRoleName(roleName);
  }
    @Override
   public List<Integer> getAllPermissionIdByRoleId(Integer roleId){

        return roleMapper.getAllPermissionIdByRoleId(roleId);
    }


    public   List<Role> listRolesByUserId(Integer userId){
        List<Role> Roles = this.list(new QueryWrapper<Role>()
                .inSql("role_id", "select role_id from user_role where user_id = " + userId));

        return Roles;


    }
}
